﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Physis.Client.Models.Insurer {

    public class InsurerModel : ApplicationModel {
                
        #region Private Properties

        private Core.Insurer.Insurer insurer = null;

        #endregion


        #region Public Properties
        
        public Int64 InsurerId {

            set {

                insurer = Application.Core.Insurer.Insurer (value);

                if (insurer == null) {

                    insurer = new Core.Insurer.Insurer (Application);

                }

            }

        }

        public Core.Insurer.Insurer Insurer { get { return insurer; } set { insurer = value; } }

        #endregion 


        #region Constructors

        public InsurerModel (Int64 forInsurerId) {

            InsurerId = forInsurerId;

            return;

        }

        public InsurerModel (System.Collections.Specialized.NameValueCollection form) {

            UpdateValues (form);

            return;

        }

        #endregion 


        #region Public Methods

        public override void UpdateValues (System.Collections.Specialized.NameValueCollection form) {

            base.UpdateValues (form);


            // RELOAD BASE OBJECT FROM DATABASE 

            InsurerId = Data.Readers.FormReader.Int64FromForm (form, "Insurer.Id");


            // IF NEW INSURER, ASSIGN READ ONLY PROPERTIES 

            if (Insurer.Id == 0) {

                Insurer.Name = Data.Readers.FormReader.StringFromForm (form, "Insurer.Name");

                Insurer.InsurerType = (Core.Insurer.Enumerations.InsurerType)Data.Readers.FormReader.Int32FromForm (form, "Insurer.InsurerType"); 

                // TODO: READ IN INITIAL ENTITY ADDRESSES 

            }


            // READ IN ASSIGNABLE PROPERTIES 

            Insurer.NationalPlanId = Data.Readers.FormReader.StringFromForm (form, "Insurer.NationalPlanId");

            Insurer.FederalTaxId = Data.Readers.FormReader.StringFromForm (form, "Insurer.FederalTaxId");

            Insurer.UniqueId = Data.Readers.FormReader.StringFromForm (form, "Insurer.UniqueId");

            Insurer.LegacyId = Data.Readers.FormReader.StringFromForm (form, "Insurer.LegacyId");
            

            return;

        }

        #endregion 

    }

}